package com.java.service.Impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.java.mapper.StudentMapper;
import com.java.po.Student;
import com.java.service.StudentService;
import com.java.util.PageUtil;

@Service
public class StudentServiceImpl implements StudentService {

	@Autowired
	private StudentMapper studentMapper;

	@Override
	public Student findByNameAndStuId(String username, int studentid, String password) {
		// TODO Auto-generated method stub
		return studentMapper.findByuserNameAndStudentId(username, studentid, password);
	}

	@Override
	public int updateStudentById(Student student) throws Exception {
		// TODO Auto-generated method stub
		return studentMapper.updateStudent(student);
	}

	@Override
	public int insertStudentOne(Student student) throws Exception {
		// TODO Auto-generated method stub
		return studentMapper.insertStudent(student);
	}

	@Override
	public int deleteStudentById(int id) throws Exception {
		// TODO Auto-generated method stub
		return studentMapper.deleteStudent(id);
	}

	@Override
	public List<Student> findListStudent(Map<String, Object> queryMap) throws Exception {
		// TODO Auto-generated method stub
		return studentMapper.findList(queryMap);
	}

	@Override
	public PageUtil<Student> findPageStudent(Map<String, Object> queryMap, int currentPage) throws SQLException {
		int record = studentMapper.record();
		PageUtil<Student> pageUtill = new PageUtil<Student>(currentPage, 10, record);
		queryMap.put("offset", pageUtill.getStartIndex());
		queryMap.put("pageSize", 10);
		List<Student> listPageUtill = studentMapper.findList(queryMap);
		pageUtill.setList(listPageUtill);
		return pageUtill;
	}

}
